 <?php

class HomeController extends Controller
{
	public function actionHome()
	{
		$this->render('home');
	}
	
	public function actionSpider(){
		$url  = 'http://www.520tingshu.com/book/book10216.html';
		$url  = 'http://www.520tingshu.com/book/book9072.html';
		$url  = 'http://www.520tingshu.com/book/book8966.html';
		$url  = 'http://www.520tingshu.com/book/book8847.html';
		$url  = 'http://www.520tingshu.com/book/book5935.html';
		$url  = 'http://www.520tingshu.com/book/book5668.html';
		$url  = 'http://www.520tingshu.com/book/book2917.html';
		$url  = 'http://www.520tingshu.com/book/book486.html';
		$content = file_get_contents($url);
		preg_match_all('/\<li\>\<a\stitle=\'.*?\'\shref=\'(.*?)\'.*?\<\/li\>/', $content, $matches);
		
		$down = $matches[1];
		$down_ary = array();
		foreach($down as $val){
			if(strpos($val, 'down')){
				$down_ary[] = 'http://www.520tingshu.com'.$val;
			}
		}
		foreach($down_ary as $url){
			$content = file_get_contents($url);
			preg_match_all('/\<script\ssrc\=\"(.*?)\"\>\<\/script\>/', $content, $matches);
			
			foreach($matches[1] as $jsUrl){
				if(strpos($jsUrl, 'playdata')){
					$jsContent = file_get_contents('http://www.520tingshu.com'.$jsUrl);
					preg_match_all('/\$(\d+)\$/', $jsContent, $downloadLinks);
					
					$d_ary = array();
					foreach($downloadLinks[1] as $link){
						$down = 'http://www.520tingshu.com/ting/tudou.asp?id='.$link;
						echo $down."<br />";
						$d_ary[] = $down;
					}
					var_dump($d_ary);
					die;
				}
			}
			
			var_dump($matches);
			die;
		}
		
	}
	
	public function actionIndex()
	{
		
		#Yii::app()->user->setFlash('success', '注册成功！');
		#$ip = Yii::app() -> ip -> getIp();
		#var_dump(Yii::app() -> ip -> find('58.24.192.17'));
		#var_dump($ip);
		#die;
		#var_dump($this -> urlShort('2'));
		#die;
		//Yii::app() -> cache -> flush();
		//$sms = Yii::app()-> sms;
		//$sms -> sendCode("18502199809");
		#var_dump($sms);
		#die;
		//首页 Banner start
		$model_banner = Banner::model();
		$banner_dataProvider = $model_banner -> search();
		$banner = array();
		foreach($banner_dataProvider -> data as $_model){
			//$banner [] = array('link'=>$_model -> Banner_Url,'image'=>$_model -> imgUrl,'label'=>$_model -> Banner_Label,'caption'=>$_model -> Banner_Text);
			$banner [] = array('link'=>$_model -> Banner_Url,'image'=>$_model -> imgUrl,'label'=>$_model -> Banner_Label );
		}
		//首页 Banner end
		
		$user = Yii::app() -> user;

		
		$audios = Audios::model()->findAll();
		
		$this->render('index',array(
				'audios'=>$audios,
				'banner'=>$banner
				));
	}
	
	
	public function actionSendmail(){
		$mail = Yii::app() -> mail;
		
		$mail->IsSMTP();                                      // set mailer to use SMTP
		$mail->Host = "smtp.qq.com";  // specify main and backup server
		$mail->SMTPAuth = true;     // turn on SMTP authentication
		$mail->Username = "noreply@bailushuo.com";  // SMTP username
		$mail->Password = "nohacker12#$"; // SMTP password
		
		#$mail->Username = "noreply@bookbag.com.cn";  // SMTP username
		#$mail->Password = "test1234"; // SMTP password
		
		#826540483
		
		#$mail->From = "noreply@bailushuo.com";
		
		$mail->From = "noreply@bailushuo.com";
		$mail->FromName = "白鹿说";
		//$mail->AddAddress("shenhongmings@gmail.com", "Alan shen");
		$mail->AddAddress("502529135@qq.com", "502529135");
		
		//$mail->AddAddress("ellen@example.com");                  // name is optional
		//$mail->AddReplyTo("info@example.com", "Information");
		
		$mail->WordWrap = 50;                                 // set word wrap to 50 characters
		#$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
		#$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
		#$mail->IsHTML(true);                                  // set email format to HTML

$body = <<<EOT
<div style="color:#333;background:#fff;font-family:Helvetica Neue,Arial,sans-serif;word-wrap:break-word;padding:0;margin:0;font-size:16px;line-height:1.6">
    <div style="padding:60px 20px;background:#42c6b8">
      <div style="max-width:600px;margin:0 auto">
        <a href="http://bailushuo.com/" style="color:#0b79e5;text-decoration:none" target="_blank">
          <u></u><u></u><u></u><u></u>
        </a>
      </div>
    </div>
    

    <div style="padding:20px 20px;background:#f9f9f9">
      <div style="max-width:600px;margin:0 auto">
        <h1 style="font-size:1.4em;font-weight:200;margin:0.67em 0;line-height:1.4">欢迎注册白鹿说</h1>
      </div>
    </div>
    
    <div style="padding:20px 20px">
      <div style="max-width:600px;margin:0 auto">
         <div> <div>
    <p>尊敬的用户：感谢您注册 <a href="http://bailushuo.com">白鹿说</a></p> 
	
	
	<div> <ul>
      <li>官网：<a href="http://www.bailushuo.com/" target="_blank">bailushuo.com</a></li>
      <li>博客：<a href="http://blog.bailushuo.cn/" target="_blank">blog.bailushuo.com</a></li>
      <li>开放资源：<a href="http://open.bailushuo.com" target="_blank">open.bailushuo.com</a></li>
      <li>技术支持：<a href="mailto:support@bailushuo.com" target="_blank">support@bailushuo.com</a></li>
      <li>合作：<a href="mailto:business@bailushuo.com" target="_blank">business@bailushuo.com</a></li>   
	  <li>疑问：<a href="mailto:qa@bailushuo.com" target="_blank">qa@bailushuo.com</a></li>   
	  <li>微博：<a href="http://weibo.com/bailushuo" target="_blank">@白鹿说</a></li>
      <li>微信：白鹿</li> </ul> </div> </div>

        <p>感谢 <br></p>
      </div>
    </div>
	
    <div style="padding:20px 20px;background:#eee;color:#666;font-size:90%">
      <div style="max-width:600px;margin:0 auto">
        <p>本邮件由 白鹿说 系统自动发出，请勿直接回复</p>
        <p></p>
        <p>如果您不想再接收此类邮件，您可以 
			<a href="#" style="color:#444" target="_blank">立即退订</a>（为了保护您的权益，帐户变更和财务相关通知邮件无法退订）
		</p>
      </div>
    </div>

  </div>
EOT;
		
		$mail->Subject = "成功注册-白鹿说";
		$mail->Body    = $body;
		$mail->AltBody = $body;
		
		if(!$mail->Send())
		{
			echo "Message could not be sent. <p>";
			echo "Mailer Error: " . $mail->ErrorInfo;
			exit;
		}
		
		echo "Message has been sent";
		die;
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}